﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                    
    xmlns:behavior="clr-namespace:PasswordProvider.View.Behaviors"
    xmlns:view="clr-namespace:PasswordProvider.View">
        
    <!-- Control template to define the look of the button which expands a group when the list box is displaying groups. -->
    <ControlTemplate x:Key="ShowGroupToggleButtonTemplate" TargetType="{x:Type ToggleButton}">
        <Border Background="{TemplateBinding Background}">
            <Grid Name="grid" Background="Transparent" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="12"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <ContentPresenter Grid.Column="1" Content="{TemplateBinding Content}" />
                <Path Name="downArrow"
                      VerticalAlignment="Center" HorizontalAlignment="Center"
                      Visibility="Collapsed" Fill="DarkGreen" Data="M 0 2 L 12 2 L 6 10 Z"/>
                <Path Name="upArrow"
                      VerticalAlignment="Center" HorizontalAlignment="Center"
                      Visibility="Collapsed" Fill="DarkRed" Data="M 0 10 L 6 2 L 12 10 Z"/>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger SourceName="downArrow" Property="IsMouseOver" Value="True">
                <Setter TargetName="downArrow" Property="Fill" Value="DarkGreen" />
            </Trigger>
            <Trigger SourceName="upArrow" Property="IsMouseOver" Value="True">
                <Setter TargetName="upArrow" Property="Fill" Value="DarkRed" />
            </Trigger>
            <Trigger Property="IsChecked" Value="False">
                <Setter TargetName="downArrow" Property="Visibility" Value="Visible" />
            </Trigger>
            <Trigger Property="IsChecked" Value="True">
                <Setter TargetName="upArrow" Property="Visibility" Value="Visible" />

            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <!-- Style to define the look of the button which opens the details view of a site. -->
    <Style x:Key="OpenItemButtonStyle" TargetType="Button">
        <Setter Property="Background" Value="{DynamicResource DetailActiveBrush}" />
        <Setter Property="Template">
            <Setter.Value>
               <ControlTemplate TargetType="{x:Type Button}">

                    <Grid Width="22" Height="14" HorizontalAlignment="Right" Background="Transparent">
                        <Viewbox Name="viewbox" HorizontalAlignment="Center" Margin="1">
                            <Path Name="path" Fill="{TemplateBinding Background}" StrokeThickness="1" Stroke="Transparent"
                      Data="M 0 4 L 5 4 L 5 0 L 20 6 L 5 12 L 5 8 L 0 8 Z"/>
                        </Viewbox>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="viewbox" Property="Margin" Value="2" />
                        </Trigger>                        
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    
    <!-- Style for the button which appears on the bottom of the sites list and shows a popup
         for creating either a new login or credit card.-->
    <Style x:Key="CreateNewSiteButtonStyle" TargetType="{x:Type ToggleButton}">

        <Setter Property="Background" Value="{DynamicResource DetailBrushLight}" />
        <Setter Property="Foreground" Value="{DynamicResource DetailBrushDark}"/>
        <Setter Property="Border.BorderBrush" Value="{DynamicResource DetailBrush}" />
        <Setter Property="Border.BorderThickness" Value="1" />
        <Setter Property="Margin" Value="0,0,3,3" />
        <Setter Property="Height" Value="17" />

        <Setter Property="Template">
            <Setter.Value>
                <!-- Control template to define the look of the button which opens the create new site popup dialog -->
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Grid>
                        <Border Height="{TemplateBinding Height}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Background="{TemplateBinding Background}">
                            <Viewbox>
                                <TextBlock Foreground="{TemplateBinding Foreground}" Margin="3,0"
                                           Text="{TemplateBinding Content}" />
                            </Viewbox>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <Style.Triggers>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="TextBlock.BitmapEffect">
                    <Setter.Value>
                        <OuterGlowBitmapEffect GlowColor="{DynamicResource DetailActiveColor}" GlowSize="2" />
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Border.BorderBrush" Value="{DynamicResource DetailActiveBrushDark}" />
                <Setter Property="Border.Background" Value="{DynamicResource DetailActiveBrush}"/>
                <Setter Property="TextBlock.Foreground" Value="{DynamicResource DetailActiveBrushDark}"/>
            </Trigger>

        </Style.Triggers>

    </Style>

    <!-- Data Template for the contents of a list box item -->
    <DataTemplate x:Key="ListBoxItemDataTemplate">
        <Grid Name="grid" HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Name="imageColumn" Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Border Name="iconBorder" Padding="0,1" Background="{DynamicResource WindowBrush}">
                <Image Name="iconImage" Grid.Column="0" Height="16" Width="16" Margin="0,1,4,1" 
                       Source="{Binding IconUrl}"/>
            </Border>
            <TextBlock Name="textBlock" Grid.Column="1" Text="{Binding Path=DisplayName}" 
					   HorizontalAlignment="Stretch" TextAlignment="Left" >
				<TextBlock.ToolTip>
					<TextBlock Text="{Binding Path=ToolTip}"/>
				</TextBlock.ToolTip>
			</TextBlock>

            <Grid Name="buttonGrid" Grid.Column="1" Width="35" HorizontalAlignment="Right" Background="Transparent">
                <Button Name="button" HorizontalAlignment="Stretch"  
                        Visibility="Collapsed"                            
                        Command="{Binding ShowSitePropertiesCommand.Command}"
                        ToolTip="{Binding ShowSitePropertiesCommand.ToolTip}"
						Style="{StaticResource OpenItemButtonStyle}" />
            </Grid>
        </Grid>
        <DataTemplate.Triggers>
            <Trigger SourceName="iconImage" Property="Source" Value="{x:Null}">
                <Setter TargetName="iconBorder" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger SourceName="grid" Property="IsMouseOver" Value="True">
                <Setter TargetName="button" Property="Visibility" Value="Visible" />
                <Setter TargetName="button" Property="Background" Value="{DynamicResource DetailActiveBrush}"/>
            </Trigger>
            <DataTrigger Binding="{Binding IsSelected}" Value="True">
                <Setter TargetName="button" Property="Background" Value="{DynamicResource DetailActiveBrushLight}"/>
            </DataTrigger>
            <Trigger SourceName="button" Property="IsMouseOver" Value="True">
                <Setter TargetName="button" Property="Background" Value="{DynamicResource DetailActiveBrushDark}"/>
            </Trigger>
        </DataTemplate.Triggers>

    </DataTemplate>

    <!-- Style for a list box item -->
    <Style x:Key="ListBoxItemContainerStyle" TargetType="ListBoxItem">
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="behavior:EventCommands.MouseDoubleClickCommand" 
                Value="{Binding NavigateToWebSiteCommand.Command}" />
        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Border Name="border" SnapsToDevicePixels="true" Margin="0">
                        <ContentPresenter />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter TargetName="border" Property="Background" Value="{DynamicResource DetailActiveBrush}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>

    <!-- Style for the expander which serves as the group item template, 
    opens and closes the groups in the sites list, when displaying groups -->
    <Style x:Key="SitesListGroupStyleExpanderStyle" TargetType="{x:Type Expander}">
        <Setter Property="Padding" Value="1,3,0,3" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Expander}">
                    <DockPanel>
                        
                        <ToggleButton DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Stretch"
                          Tag="{Binding Name}" Background="Transparent"
                          Template="{StaticResource ShowGroupToggleButtonTemplate}"
                          IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                          >

                            <WrapPanel Style="{StaticResource ListBoxGroupHeaderStyle}">
                                <TextBlock Name="nameTextBlock" Margin="5,0,0,0" Text="{Binding Path=Name}"/>
                                <TextBlock Margin="7,0,0,0" Text="("/>
                                <TextBlock Text="{Binding Path=ItemCount}"/>
                                <TextBlock Text=")"/>
                            </WrapPanel>

                        </ToggleButton>
                        <ContentPresenter Name="ExpandSite" DockPanel.Dock="Bottom" Visibility="Collapsed" Focusable="false" 
                                          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                                          Margin="{TemplateBinding Padding}" />
                    </DockPanel>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="true">
                            <Setter TargetName="ExpandSite" Property="Visibility" Value="Visible" />
                        </Trigger>

                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style x:Key="HyperlinkStyle" TargetType="Hyperlink">
        <Setter Property="Foreground" Value="{DynamicResource DetailActiveBrushDark}"/>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Foreground" Value="{DynamicResource DetailActiveBrush}"/>
            </Trigger>
        </Style.Triggers>
    </Style>
    
    <!-- Style for the list box on the sites list box page -->
    <Style x:Key="SitesListViewListBoxStyle" TargetType="{x:Type ListBox}">
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="SelectionMode" Value="Single" />
        <Setter Property="ItemContainerStyle" Value="{StaticResource ListBoxItemContainerStyle}" />
        <Setter Property="ItemTemplate" Value="{StaticResource ListBoxItemDataTemplate}" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />     
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBox}">
                    <ScrollViewer VerticalScrollBarVisibility="Auto">
                        <Grid >
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <ItemsPresenter Name="presenter" Grid.Row="0" />

                            <ToggleButton Name="newButton" Grid.Row="1"
                                              IsChecked="{Binding ElementName=popup, Path=IsOpen}"
                                              Style="{DynamicResource CreateNewSiteButtonStyle}"
                                              HorizontalAlignment="Right" VerticalAlignment="Bottom"
                                              Content="Create New Site">
                            </ToggleButton>
                            <Border Name="marker" Grid.Row="1" Width="0" Height="0" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
                            <Popup Grid.Row="1" Name="popup" StaysOpen="False"
                                       AllowsTransparency="True"
                                       PlacementTarget="{Binding ElementName=marker}"
                                       Placement="Left" VerticalOffset="-75" 
                                       PopupAnimation="Fade">
                                <Border Name="border" Padding="10,5"  
                                        BorderThickness="1"
                                        BorderBrush="{DynamicResource DetailActiveBrushDark}"
                                        Background="{DynamicResource DetailActiveBrushLight}">
                                    <StackPanel Name="stackPanel">
                                        <TextBlock Margin="0">
                                            <Hyperlink Style="{StaticResource HyperlinkStyle}" 
                                                       Command="{Binding CreateNewLogOnSiteCommand.Command}">
                                                <TextBlock Text="{Binding CreateNewLogOnSiteCommand.DisplayName}"/>
                                            </Hyperlink>
                                        </TextBlock>
                                        <TextBlock Margin="0,5,0,0">
                                            <Hyperlink Style="{StaticResource HyperlinkStyle}" 
                                                       Command="{Binding CreateNewCreditCardCommand.Command}">
                                                <TextBlock Text="{Binding CreateNewCreditCardCommand.DisplayName}"/>
                                            </Hyperlink>
                                        </TextBlock>
                                        <TextBlock Margin="0,5,0,0">
                                            <Hyperlink Style="{StaticResource HyperlinkStyle}" 
                                                       Command="{Binding CreateNewGenericSiteCommand.Command}">
                                                <TextBlock Text="{Binding CreateNewGenericSiteCommand.DisplayName}"/>
                                            </Hyperlink>
                                        </TextBlock>
                                    </StackPanel>
                                </Border>
                            </Popup>

                        </Grid>
                    </ScrollViewer>
                    <ControlTemplate.Triggers>
                        <Trigger SourceName="popup" Property="IsOpen" Value="True">
                            <Setter TargetName="newButton" Property="Opacity" Value="0" />
                        </Trigger>
                    </ControlTemplate.Triggers>

                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>


</ResourceDictionary>